using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;

namespace WindowsFormsApp1
{
    public partial class EduBaseDemo : DbContext
    {
        public EduBaseDemo()
            : base("name=EduBaseDemo")
        {
        }

        public virtual DbSet<tb_Class> tb_Class { get; set; }
        public virtual DbSet<tb_Course> tb_Course { get; set; }
        public virtual DbSet<tb_Department> tb_Department { get; set; }
        public virtual DbSet<tb_Major> tb_Major { get; set; }
        public virtual DbSet<tb_Student> tb_Student { get; set; }
        public virtual DbSet<tb_Score> tb_Score { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<tb_Class>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<tb_Class>()
                .HasMany(e => e.tb_Student)
                .WithRequired(e => e.tb_Class)
                .HasForeignKey(e => e.ClassNo)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tb_Course>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<tb_Department>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<tb_Department>()
                .HasMany(e => e.tb_Major)
                .WithRequired(e => e.tb_Department)
                .HasForeignKey(e => e.DepartmentNo)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tb_Major>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<tb_Major>()
                .HasMany(e => e.tb_Class)
                .WithRequired(e => e.tb_Major)
                .HasForeignKey(e => e.MajorNo)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tb_Student>()
                .Property(e => e.No)
                .IsFixedLength()
                .IsUnicode(false);

            modelBuilder.Entity<tb_Student>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<tb_Score>()
                .Property(e => e.StuNo)
                .IsFixedLength()
                .IsUnicode(false);

            modelBuilder.Entity<tb_Score>()
                .Property(e => e.PinshiScore)
                .HasPrecision(3, 1);

            modelBuilder.Entity<tb_Score>()
                .Property(e => e.QimoScore)
                .HasPrecision(3, 1);

            modelBuilder.Entity<tb_Score>()
                .Property(e => e.ZongpingScore)
                .HasPrecision(3, 1);

            modelBuilder.Entity<tb_Score>()
                .Property(e => e.PinjiaoScore)
                .HasPrecision(3, 1);
        }
    }
}
